package cloudy.tools;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Package prictice.base
 * @Description:
 * @Author elwyn
 * @Date 2017/9/17 16:28
 * @Email elonyong@163.com
 */
public class DateFmt {
    public static final String date_long = "yyyy-MM-dd HH:mm:ss";
    public static final String date_short = "yyyy-MM-dd";
    public static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(date_short);

    public static String getCountDate(String date, String patton) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(patton);
        Calendar calendar = Calendar.getInstance();
        if (date != null) {
            try {
                calendar.setTime(simpleDateFormat.parse(date));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return simpleDateFormat.format(calendar.getTime());
    }

    public static Date parseDate(String dateStr) throws ParseException {
        return simpleDateFormat.parse(dateStr);
    }
}
